<template>
    <a-spin :spinning="confirmLoading">
        <j-form-container :disabled="formDisabled">
            <a-form slot="detail" :form="form">
                <a-row>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="车牌号">
                            <a-input v-decorator="['plateNo']" placeholder="请输入车牌号"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="挂车号">
                            <a-input v-decorator="['trailerNo']" placeholder="请输入挂车号"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="司机姓名">
                            <a-input v-decorator="['driverName']" placeholder="请输入司机姓名"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="手机号">
                            <a-input v-decorator="['phoneNum']" placeholder="请输入手机号"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="产品种类">
                            <a-input v-decorator="['productionType']" placeholder="请输入产品种类"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="车队">
                            <a-input v-decorator="['fleet']" placeholder="请输入车队"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="收货企业名称">
                            <a-input v-decorator="['receiptCompany']" placeholder="请输入收货企业名称"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="是否有食用油专用标签">
                            <j-dict-select-tag v-decorator="['isEdibleOilLabel']" :trigger-change="true"
                                dictCode="isEdibleOilLabel" placeholder="请选择是否有食用油专用标签" type="radio" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="健康证">
                            <j-image-upload v-decorator="['healthCertificate']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="前一载卸货公司">
                            <a-input v-decorator="['lastTimeUnloadingCompanyName1']" placeholder="请输入前一载卸货公司"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="前一载卸车货品名称">
                            <a-input v-decorator="['lastTimeUnloadingGoodsName1']" placeholder="请输入前一载卸车货品名称"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="前一载卸货日期">
                            <j-date :show-time="true" v-decorator="['lastTimeUnloadingDate1']" :trigger-change="true"
                                date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择前一载卸货日期" style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="前二载卸货公司">
                            <a-input v-decorator="['lastTimeUnloadingCompanyName2']" placeholder="请输入前二载卸货公司"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="前二载卸车货品名称">
                            <a-input v-decorator="['lastTimeUnloadingGoodsName2']" placeholder="请输入前二载卸车货品名称"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="前二载卸货日期">
                            <j-date :show-time="true" v-decorator="['lastTimeUnloadingDate2']" :trigger-change="true"
                                date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择前二载卸货日期" style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="前三载卸货公司">
                            <a-input v-decorator="['lastTimeUnloadingCompanyName3']" placeholder="请输入前三载卸货公司"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="前三载卸车货品名称">
                            <a-input v-decorator="['lastTimeUnloadingGoodsName3']" placeholder="请输入前三载卸车货品名称"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="前三载卸货日期">
                            <j-date :show-time="true" v-decorator="['lastTimeUnloadingDate3']" :trigger-change="true"
                                date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择前三载卸货日期" style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="三载卸货照片">
                            <j-image-upload v-decorator="['lastTimeUnloadingPhotos']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="前三载证明文件">
                            <j-image-upload v-decorator="['documentation']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="上次清洗时间">
                            <j-date v-decorator="['lastTimeCleaningDate']" :show-time="true" :trigger-change="true"
                                date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择上次清洗时间" style="width: 100%" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="上次清洗证明">
                            <j-image-upload v-decorator="['lastTimeCleaningPhotos']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="清洗公司">
                            <a-input v-decorator="['cleanCompany']" placeholder="清洗公司"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="车头拍照号照片">
                            <j-image-upload v-decorator="['cleanPhoto1']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="挂车牌照号照片">
                            <j-image-upload v-decorator="['cleanPhoto2']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="清罐场地照片">
                            <j-image-upload v-decorator="['cleanPhoto3']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="人员着装照片">
                            <j-image-upload v-decorator="['cleanPhoto4']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="作业场景照片">
                            <j-image-upload v-decorator="['cleanPhoto5']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="司机签字">
                            <j-image-upload v-decorator="['driverSign']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="司机承诺视频">
                            <j-image-upload v-decorator="['driverVideo']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="车辆正面斜45度照片">
                            <j-image-upload v-decorator="['vehicle45Photo']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="车辆背面斜45度照片">
                            <j-image-upload v-decorator="['back45Photo']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="车身照片">
                            <j-image-upload v-decorator="['vehiclePhoto']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="罐内照片">
                            <j-image-upload v-decorator="['tankPhoto']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="卸油口照片">
                            <j-image-upload v-decorator="['oilDischargePortPhoto']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="是否异味 ">
                            <j-dict-select-tag v-decorator="['isOdor']" :trigger-change="true" dictCode="isOdor"
                                placeholder="请输入是否异味" type="radio" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="检验意见">
                            <a-input v-decorator="['opinion']" placeholder="请输入检验意见"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="佐证图片">
                            <j-image-upload v-decorator="['evidencePic']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="铅封照片">
                            <j-image-upload v-decorator="['leadSealingPic']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="销售出库单">
                            <j-image-upload v-decorator="['salesOrder']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="散装食用植物油运输随车装运记录表">
                            <j-image-upload v-decorator="['onboardRecordForm']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="重量">
                            <a-input v-decorator="['weight']" placeholder="请输入重量"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="铅封人员">
                            <a-input v-decorator="['leadSealingName']" disabled placeholder="请输入铅封人员"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="一次审核人员">
                            <a-input v-decorator="['auditName1']" placeholder="请输入一次审核人员" disabled></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="审核品质经理">
                            <a-input v-decorator="['auditName2']" placeholder="请输入审核品质经理" disabled></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="审核业务经理">
                            <a-input v-decorator="['auditName3']" placeholder="请输入审核业务经理" disabled></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="一次检验人员">
                            <a-input v-decorator="['surveyorName1']" disabled placeholder="请输入一次检验人员"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="二次检验人员">
                            <a-input v-decorator="['surveyorName2']" disabled placeholder="请输入二次检验人员"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="gps截图">
                            <j-image-upload v-decorator="['screenshot']" isMultiple></j-image-upload>
                        </a-form-item>
                    </a-col>
                    <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
                        <a-button @click="submitForm">提 交</a-button>
                    </a-col>
                </a-row>
            </a-form>
        </j-form-container>
    </a-spin>
</template>

<script>

import { getAction, httpAction } from '@/api/manage'
import pick from 'lodash.pick'

export default {
    name: 'TankerRegistrationForm',
    components: {},
    props: {
        //流程表单data
        formData: {
            type: Object,
            default: () => {
            },
            required: false
        },
        //表单模式：true流程表单 false普通表单
        formBpm: {
            type: Boolean,
            default: false,
            required: false
        },
        //表单禁用
        disabled: {
            type: Boolean,
            default: false,
            required: false
        }
    },
    data() {
        return {
            form: this.$form.createForm(this),
            model: {},
            labelCol: {
                xs: { span: 24 },
                sm: { span: 5 },
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 16 },
            },
            confirmLoading: false,
            validatorRules: {},
            url: {
                add: "/tankerRegistration/tankerRegistration/add",
                edit: "/tankerRegistration/tankerRegistration/edit",
                queryById: "/tankerRegistration/tankerRegistration/queryById"
            },
        }
    },
    computed: {
        formDisabled() {
            if (this.formBpm === true) {
                if (this.formData.disabled === false) {
                    return false
                }
                return true
            }
            return this.disabled
        },
        showFlowSubmitButton() {
            if (this.formBpm === true) {
                if (this.formData.disabled === false) {
                    return true
                }
            }
            return false
        }
    },
    created() {
        //如果是流程中表单，则需要加载流程表单data
        this.showFlowData();
    },
    methods: {
        add() {
            this.edit({});
        },
        edit(record) {
            this.form.resetFields();
            this.model = Object.assign({}, record);
            this.visible = true;
            this.$nextTick(() => {
                this.form.setFieldsValue(pick(this.model, 'plateNo', 'driverName', 'phoneNum', 'fleet', 'isEdibleOilLabel',
                    'lastTimeUnloadingCompanyName1', 'lastTimeUnloadingGoodsName1', 'lastTimeUnloadingDate1', 'lastTimeUnloadingCompanyName2',
                    'lastTimeUnloadingGoodsName2', 'lastTimeUnloadingDate2', 'lastTimeUnloadingCompanyName3', 'lastTimeUnloadingGoodsName3',
                    'lastTimeUnloadingDate3', 'lastTimeUnloadingPhotos', 'lastTimeCleaningDate', 'lastTimeCleaningPhotos', 'driverSign',
                    'auditStatus', 'entryStatus', 'entryTime', 'entryPic', 'exitTime', 'exitPic', 'vehicle45Photo', 'tankPhoto',
                    'oilDischargePortPhoto', 'isOdor', 'auditDate', 'surveyorName', 'surveyorDate', 'driverVideo', 'opinion', 'evidencePic',
                    'leadSealingPic', 'leadSealingName', 'auditName1', 'auditName2', 'auditName3', 'surveyorName1', 'surveyorName2', 'productionType',
                    'trailerNo', 'salesOrder', 'back45Photo', 'vehiclePhoto', 'healthCertificate', 'documentation', 'screenshot', 'onboardRecordForm',
                    'weight', 'receiptCompany', 'deliverCompany', 'checkResult', 'lastUnqualifiedMark', 'cleanCompany', 'cleanPhoto1',
                    'cleanPhoto2', 'cleanPhoto3', 'cleanPhoto4', 'cleanPhoto5'))
            })
        },
        //渲染流程表单数据
        showFlowData() {
            if (this.formBpm === true) {
                let params = { id: this.formData.dataId };
                getAction(this.url.queryById, params).then((res) => {
                    if (res.success) {
                        this.edit(res.result);
                    }
                });
            }
        },
        submitForm() {
            const that = this;
            // 触发表单验证
            this.form.validateFields((err, values) => {
                if (!err) {
                    that.confirmLoading = true;
                    let httpurl = '';
                    let method = '';
                    if (!this.model.id) {
                        httpurl += this.url.add;
                        method = 'post';
                    } else {
                        httpurl += this.url.edit;
                        method = 'put';
                    }
                    let formData = Object.assign(this.model, values);
                    console.log("表单提交数据", formData)
                    httpAction(httpurl, formData, method).then((res) => {
                        if (res.success) {
                            that.$message.success(res.message);
                            that.$emit('ok');
                        } else {
                            that.$message.warning(res.message);
                        }
                    }).finally(() => {
                        that.confirmLoading = false;
                    })
                }

            })
        },
        popupCallback(row) {
            this.form.setFieldsValue(pick(row, 'plateNo', 'driverName', 'phoneNum', 'fleet', 'isEdibleOilLabel', 'lastTimeUnloadingCompanyName1',
                'lastTimeUnloadingGoodsName1', 'lastTimeUnloadingDate1', 'lastTimeUnloadingCompanyName2', 'lastTimeUnloadingGoodsName2',
                'lastTimeUnloadingDate2', 'lastTimeUnloadingCompanyName3', 'lastTimeUnloadingGoodsName3', 'lastTimeUnloadingDate3',
                'lastTimeUnloadingPhotos', 'lastTimeCleaningDate', 'lastTimeCleaningPhotos', 'driverSign', 'auditStatus', 'entryStatus',
                'entryTime', 'entryPic', 'exitTime', 'exitPic', 'vehicle45Photo', 'tankPhoto', 'oilDischargePortPhoto', 'isOdor', 'auditDate',
                'surveyorName', 'surveyorDate', 'driverVideo', 'opinion', 'evidencePic', 'leadSealingPic', 'leadSealingName', 'auditName1',
                'auditName2', 'auditName3', 'surveyorName1', 'surveyorName2', 'productionType', 'trailerNo', 'salesOrder', 'back45Photo',
                'vehiclePhoto', 'healthCertificate', 'documentation', 'screenshot', 'onboardRecordForm', 'weight', 'receiptCompany',
                'deliverCompany', 'checkResult', 'lastUnqualifiedMark', 'cleanCompany', 'cleanPhoto1', 'cleanPhoto2', 'cleanPhoto3',
                'cleanPhoto4', 'cleanPhoto5'))
        },
    }
}
</script>